extends Node2D

onready var bao_xiang = load("res://baoxiang.tscn")
onready var bomb = load("res://Bomb.tscn")
onready var pos = $Position2D
onready var pos2 = $Position2D2
onready var pos3 = $Position2D3

func _ready():
	pass

func move_player(index):
	var player = $Human
	if index == 1:
		player.position.x = pos.position.x
	elif index == 2:
		player.position.x = pos2.position.x
	elif index == 3:
		player.position.x = pos3.position.x
	player.position.y -= 64
	pass
	
func _on_Button_pressed():
	move_player(1)
	gen_at(1)
	pass


func _on_Button2_pressed():
	gen_at(2)
	move_player(2)
	pass


func _on_Button3_pressed():
	gen_at(3)
	move_player(3)
	pass

func gen_bao_or_bomb(p_pos):
	var r = randi() %2
	if r == 0:
		var bao = bao_xiang.instance()
		bao.position = p_pos
		add_child(bao)
	if r == 1:
		var bomb_instance = bomb.instance()
		bomb_instance.position = p_pos
		add_child(bomb_instance)
			
func gen_at(index:int):
	var true_index = index-1
	var gen_pos = get_child(true_index).position
	print_debug(gen_pos)
	gen_bao_or_bomb(gen_pos)
	pass
